<?php
/* @var $this CategoryController */
/* @var $model Category */

$this->breadcrumbs=array(
	'Categories'=>array('index'),
	'Manage',
);
?>
<div class="contentwrapper"><!--Content wrapper-->
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <p><strong>
            <span class="icon16  brocco-icon-mic"></span>
            <?php echo t('You may optionally enter a comparison operator at the beginning of each of your search values to specify how the comparison should be done.','search'); ?>
        </strong></p>
    </div>
    <?php
    $this->widget('bootstrap.widgets.TbExtendedGridView', array(
        'filter'=>$model,
        'sortableRows'=>true,
        'afterSortableUpdate' => 'js:function(id, position){ console.log("id: "+id+", position:"+position);}',
        'type'=>'striped bordered',
        'dataProvider' => $model->search(),
        'template' => "{pager}\n{items}\n{extendedSummary}\n{pager}",
        'id'=>'category-grid',
        'responsiveTable'=>true,
        'bulkActions' => array(
            'actionButtons' => array(
                array(
                    'buttonType' => 'button',
                    'type' => 'primary',
                    'size' => 'small',
                    'label' => t('Delete','fcms'),
                    'click' => 'js:function(checked){
                     var values = [];
                     checked.each(function(){
                         values.push($(this).val());
                     });
                    bootbox.confirm("'.t('Are you sure that you want to permanently delete the selected categories ?','fcms').'", function(result) {
                  if(result){
                  $.ajax({
                     url:"'.url('/category/batchDelete').'",
                     cache:false,
                     type:"POST",
                     data: {ids:values.join(","),'.csrfTokenName().':"'.csrfToken().'"},
                     success:function(data){
                            $("#category-grid").yiiGridView("update");
                            var json = jQuery.parseJSON(data);
                            jQuery.each(json,function(index,item){
                                if(item.status == false) {
                                    var html = "<div><div class=\"alert in alert-block fade alert-error\"><a class=\"close\" data-dismiss=\"alert\">×</a><span class=\"label label-important\">Error</span> "+item.message+" </div></div>";
                                    $(".fix-float-left").prepend($(html).fadeIn("slow").delay(30000).fadeOut("slow"));
                                }else if(item.status == true){
                                    var html = "<div><div class=\"alert in alert-block fade alert-success\"><a class=\"close\" data-dismiss=\"alert\">×</a><span class=\"label label-success\">Success</span> "+item.message+" </div></div>";
                                    $(".fix-float-left").prepend($(html).fadeIn("slow").delay(30000).fadeOut("slow"));
                                }
                            });
                        }
                        });
                      }
                    });
                }'
                )
            ),
            // if grid doesn't have a checkbox column type, it will attach
            // one and this configuration will be part of it
            'checkBoxColumnConfig' => array(
                'name' => 'id',
                'checkBoxHtmlOptions'=>array('class'=>'nostyle')
            ),
        ),
        'columns' => array(
            array(
                'class'=>'bootstrap.widgets.TbRelationalColumn',
                'name' => 'name',
                'url' => $this->createUrl('category/relational'),
                'value'=> array($model,'renderName'),
                'filter'=> $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                    //'name'=>'title',
                    'id'=>'titleAutoComplete',
                    'model'=>$model,
                    'attribute'=>'name',
                    'sourceUrl'=>url('/category/autocomplete'),
                    'options'=>array(
                        'minLength'=>'2',
                    ),
                    'htmlOptions'=>array(
                        'size'=>'36',
                    ),
                ), true),
                'type'=>'raw',
                'htmlOptions'=>array('style'=>'text-align:left'),
            ),
            /*array(
                'name'=>'name',
                'value'=>array($model,'renderName'),
                'htmlOptions'=>array('style'=>'text-align:left'),
                'type'=>'raw',
            ),*/
            array(
                'name'=>'id',
                'headerHtmlOptions'=>array('width'=>'30px')
            ),
            array(
                'name'=>'is_active',
                'value'=>array($model,'renderStatus'),
                'filter' => CHtml::activeDropDownList($model, 'is_active', array('No filter' => 'All', 1 => 'Active', 0 => 'Deactivate'), array('class'=>'nostyle')),
                'headerHtmlOptions'=>array('width'=>'80px'),
                'type'=>'raw',
            ),
            array(
                'class'=>'bootstrap.widgets.TbButtonColumn',
                'template' => '{update}{delete}',
                'afterDelete'=>'function(link,success,data){
                var json = jQuery.parseJSON(data);
                jQuery.each(json,function(index,item){
                    if(item.status == false) {
                        var html = "<div><div class=\"alert in alert-block fade alert-error\"><a class=\"close\" data-dismiss=\"alert\">×</a><span class=\"label label-important\">Error</span> "+item.message+" </div></div>";
                        $(".fix-float-left").prepend($(html).fadeIn("slow").delay(30000).fadeOut("slow"));
                    }else if(item.status == true){
                        var html = "<div><div class=\"alert in alert-block fade alert-success\"><a class=\"close\" data-dismiss=\"alert\">×</a><span class=\"label label-success\">Success</span> "+item.message+" </div></div>";
                        $(".fix-float-left").prepend($(html).fadeIn("slow").delay(30000).fadeOut("slow"));
                    }
                });
                }',
            )),
    ))
    ?>
</div><!-- End #Contenwapper -->

